#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_beta2.info <<'%EOF%'
   cc_rsp_beta2
   ------------
   Molecule:         HF in C2
   Wave Function:    CCS, CCSD / 6-31G**
   Test Purpose:     - Parallel (beta_|| ) and orthogonal averages (beta_|_)
                     - A & B coefficients 
                     - Frozen-core approximation for hyperpolarizabilities
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_beta2.mol <<'%EOF%'
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    1  Y         1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_beta2.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**WAVE FUNCTIONS
.TITLE
  first hyperpolarizability for the HF molecule
  for CCS and CCSD wavefunctions compute:
  - parallel (beta_|| ) and orthogonal averages (beta_|_)
  - A & B coefficients  (2. and 4. order dispersion coefficients)
  - core orbital frozen
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.CCSD
.THRENR
 1.0d-8
.THRLEQ
 1.0d-8
.NSYM
 2
.FROIMP
 1 0 0 0
 0 0 0 0
*CCQR
.AVERAGE
HYPERPOLARIZABILITY
.DISPCF
  4
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_beta2.check
cat >>cc_rsp_beta2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Total SCF   energy:                  \-100.008919(8|9)." $log | wc -l`
CRIT2=`$GREP "Total MP2   energy:                  \-100.19214(79|80)." $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy:                  \-100.196477(7|8)." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=7
ERROR[1]="ENERGIES NOT CORRECT"


# static CCS hyperpolarizabilities
CRIT1=`$GREP "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000      16.5744" $log | wc -l`
CRIT2=`$GREP "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000     ..675512" $log | wc -l`
CRIT3=`$GREP "beta_\|\| * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 10.7552" $log | wc -l`
CRIT4=`$GREP "beta.K * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 10.7552" $log | wc -l`
CRIT5=`$GREP "beta_\|_ * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 3.58509" $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5` 
CTRL[2]=5
ERROR[2]="STATIC CCS FIRST HYPERPOLARIZABILITIES NOT CORRECT"

# CCS hyperpolarizability disperion coefficients
CRIT1=`$GREP "2    29.5400(4|5).       3.86068(0|1).       12.83968." $log | wc -l`
CRIT2=`$GREP "4    679.245..       20.9199(3|4).       110.350(7|8)." $log | wc -l`
CRIT3=`$GREP "2    167.251(0|1).       55.7503(6|7).       55.7503(6|7)." $log | wc -l`
CRIT4=`$GREP "4    2169.282.       241.031(3|4).       241.031(3|4)." $log | wc -l`
CRIT5=`$GREP "beta\(0\)   10.75528" $log | wc -l`
CRIT6=`$GREP "A         2.591766" $log | wc -l`
CRIT7=`$GREP "B         5.60262(6|7|8)" $log | wc -l`
CRIT8=`$GREP "A       ..83484(5|6).." $log | wc -l`
CRIT9=`$GREP "B        4.15753..         B.     ( \-|\-0)\.70692(6|7).." $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9` 
CTRL[3]=11
ERROR[3]="CCS FIRST HYPERPOLARIZABILITIES DISPERSION COEFFICIENTS NOT CORRECT"


# static CCSD hyperpolarizabilities
CRIT1=`$GREP "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000      15.3829" $log | wc -l`
CRIT2=`$GREP "ZDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000   XDIPLEN  \(unrel\.\) (\-0| \-| 0|  )\.0000     ..902848" $log | wc -l`
CRIT3=`$GREP "beta_\|\| * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 10.3132" $log | wc -l`
CRIT4=`$GREP "beta.K * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 10.3132" $log | wc -l`
CRIT5=`$GREP "beta_\|_ * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * 3.43773" $log | wc -l`
TEST[4]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5` 
CTRL[4]=5
ERROR[4]="STATIC CCSD FIRST HYPERPOLARIZABILITIES NOT CORRECT"

# CCSD hyperpolarizability disperion coefficients
CRIT1=`$GREP "2    45.482(09|10).       6.43895..       19.5215(6|7)." $log | wc -l`
CRIT2=`$GREP "4    1253.837.       41.952(4|5)..       201.168(4|5)." $log | wc -l`
CRIT3=`$GREP "2    188.1976.       62.7325(3|4).       62.7325(3|4)." $log | wc -l`
CRIT4=`$GREP "4    2909.4(6|7)..       323.274(4|5).       323.274(4|5)." $log | wc -l`
CRIT5=`$GREP "beta\(0\)   10.31321" $log | wc -l`
CRIT6=`$GREP "A         3.041366" $log | wc -l`
CRIT7=`$GREP "B         7.83641." $log | wc -l`
CRIT8=`$GREP "A        1.268528." $log | wc -l`
CRIT9=`$GREP "B        7.71902..         B.      \-1.27717(4|5)." $log | wc -l`
TEST[5]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9` 
CTRL[5]=11
ERROR[5]="CCSD FIRST HYPERPOLARIZABILITIES DISPERSION COEFFICIENTS NOT CORRECT"


# symmetry of beta tensor:
CRIT1=`$GREP "beta_ms * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000 * (\-0|\-|0| )\.0000" $log | \
       awk "\\\$5 < 1.0e-12 {print \\\$0}" | wc -l`
CRIT2=`$GREP "beta_ms                                    0" $log | \
       awk "NF==5 && \\\$3+\\\$4+\\\$5 < 1.0e-12 {print \\\$0}" | wc -l`
TEST[6]=`expr $CRIT1 \+ $CRIT2`
CTRL[6]=4
ERROR[6]="SYMMETRY OF HYPERPOLARIZABILITY TENSOR NOT CORRECT"


PASSED=1
for i in 1 2 3 4 5 6
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
chmod +x cc_rsp_beta2.check
#######################################################################
